﻿using Bll;
using Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using Utils;
using Vote.Models;

namespace Vote.Controllers
{
    public class BaseController:Controller
    {
        JavaScriptSerializer Serializer = new JavaScriptSerializer();
        public UserInfoModel CurrentUser
        {
            get
            {
                if (Request.Cookies["UserInfo"] != null)
                {
                    //return CurrentUser as UserInfo;
                    //cookie.Expires = DateTime.Now.AddHours(1);
                    UserInfoModel userinfo = Serializer.Deserialize<UserInfoModel>(Server.UrlDecode(Request.Cookies["UserInfo"].Value));
                    return userinfo;
                }
                else
                {
                    return null;
                }
            }
            set
            {
                if (value != null)
                {
                    HttpCookie userCookie = new HttpCookie("UserInfo");
                    userCookie.Value = Server.UrlEncode(Serializer.Serialize(value));
                    HttpContext.Response.Cookies.Add(userCookie);
                }
            }
        }
    }
}